from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from .models import *
from .serializers import DepartmentSerializers
from django.conf import settings

class DepartmentTypeView(APIView):
    def get(self,request):
        type=settings.DEPARTMENT_CLASSIFICATION.values()
        return Response(list(type))

class DepartmentView(ModelViewSet):
    queryset = Department.objects.all()
    serializer_class = DepartmentSerializers
    # def get_queryset(self):
    #     queryinfo=self.request.query_params.get('queryinfo')
    #     if queryinfo=='all':
    #         self.pagination_class=None
    #     print(queryinfo)
    #     return  self.queryset

    @action(methods=['get'], detail=False)
    def getCollege(self,request):
        queryset=Department.objects.filter(type=settings.DEPARTMENT_CLASSIFICATION['COLLEGE']['id'])
        ser = self.get_serializer(queryset, many=True)

        return Response(ser.data)